package com.suixun.result;

import java.io.Serializable;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.suixun.enums.ApiCode;

/**
 * 功能描述: 结果操作集
 * 
 * @author jacky
 * @date 2018年1月6日上午9:51:20
 */
public class Result implements Serializable {

	private static final long serialVersionUID = 7327925821361029050L;

	private int code = ApiCode.HTTP_200.getCode();

	private String msg;

	private Object data;
	
	public Result(){}
	
	public Result(ApiCode _code, Object _data){
        this.msg = _code.getMsg();
        this.code = _code.getCode();
        this.data = _data;
    }

	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public void setMsg(Exception ex) {
		if (ex.getCause() == null) {
			this.msg = ex.getMessage();
		} else {
			this.msg = ex.getMessage() + " - " + ex.getCause();
		}
	}

	public Object getData() {
		return data;
	}

	@JsonProperty("data")
	public void setData(Object data) {
		this.data = data;
	}
}
